<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>是否选中</button>
    <hr />
    <input type="checkbox" />
    <script>
      var button = document.querySelector('button')
      var input = document.querySelector('input')
      var flag = '没有打勾'
      button.onclick = function () {
        if (flag === '没有打勾') {
          input.checked = true
          flag = '打勾了'
        } else if (flag === '打勾了') {
          input.checked = false
          flag = '没有打勾'
        }
      }
    </script>
  </body>
</html>
